package com.dc2013.followme;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CusotmSpinnerAdapter extends BaseAdapter 
{

	private TextView title;
	private ArrayList<SpinnerItem> spinnerItem;
	private Context context;
	private LayoutInflater inflater;
	private int layout;
	
	public CusotmSpinnerAdapter(Context context,int layout,ArrayList<SpinnerItem> spinnerItem)
	{
		this.spinnerItem = spinnerItem;
		this.context = context;
		this.layout= layout;
		inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	@Override
	public int getCount() 
	{
		return spinnerItem.size();
	}

	@Override
	public Object getItem(int index) 
	{
		return spinnerItem.get(index);
	}

	@Override
	public long getItemId(int position) 
	{
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{
		if(convertView == null)
		{
			LayoutInflater mInflater = (LayoutInflater)context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
			convertView = mInflater.inflate(R.layout.spinner_item_layout,null);
		}
		
		title = (TextView)convertView.findViewById(R.id.spinner_title);
		title.setText(spinnerItem.get(position).getTitle());
		
		return convertView;

	}
	
	  public View getDropDownView(int position, View convertView, ViewGroup parent)
	  {
	        if (convertView == null) 
	        {
	        	convertView = inflater.inflate(layout, parent,false);
	        }
	         
	        
	        title = (TextView) convertView.findViewById(R.id.spinner_title);  
	        title.setText(spinnerItem.get(position).toString());
	        return convertView;
	    }

}
